'use strict';

import * as actions from '../../actions/mjs1';

// 对页面prop 数据进行管理
const initialState = {
  creating: false,
  error:false,
  loginError:false,
  message:"",
  zType:"decreaseAmount",
  area:[],
  decrease_amount	:0,
  discount_rate	:0,
  end_time	:"",
  exclude_area	:[],
  gift_id	:0,
  gift_name	:"",
  gift_url	:"",
  is_amount_multiple	:'false',
  is_amount_over	:true,
  is_decrease_money	:true,
  is_discount	:false,
  is_free_post	:'false',
  is_item_count_over	:false,
  is_item_multiple	:'false',
  is_send_gift	:'false',
  is_shop_member	:'false',
  is_user_tag	:'false',
  item_count	:0,
  name	:"",
  participate_range	:"1",
  shop_member_level	:0,
  start_time	:"",
  total_price	:0,
  type	:1,
  user_tag	:"",
  
};
const defaultAction = {
  type: 'doNothing'
};

export default function index(state = initialState, action = defaultAction ) {
  switch (action.type) {
    case actions.SET_FIELD:
      return Object.assign({}, state, {
        [action.name]:action.value
      });
	  break;
    case actions.SET_ZHEKOU_TYPE:
      return Object.assign({}, state, {
        zType:action.value
      });
	  break;
    case actions.CREAT_ZHEKOU_START:
      return Object.assign({}, state, {
        creating:true,
        error:false,
        loginError:false,
		actionDone:false
      });
	  break;
    case actions.CREAT_ZHEKOU_SET_ITEMS:
	  return Object.assign({}, state, {
        creating:false,
        error:false,
        loginError:false,
        activityId:action.activityId,
		needItems:action.needItems,
		actionDone:action.actionDone
      });
	  break;
    case actions.CREAT_ZHEKOU_NEED_ITEMS:
	  return Object.assign({}, state, {
        creating:false,
        error:false,
        loginError:false,
		needItems:action.needItems
      });
	  break;
    case actions.CREAT_ZHEKOU_DONE:
      return Object.assign({}, state, {
        creating:false,
        error:false,
        loginError:false,
		data:action.data,
        activityId:action.activityId,
        dbId:action.id,
		actionDone:action.actionDone
      });
	  break;
    case actions.CREAT_ZHEKOU_ERR:
      return Object.assign({}, state, {
        creating:false,
		error:true,
		loginError:action.loginFalse,
		message:action.message
      });
	  break;
    case actions.CLOSE_DIALOG:
      return Object.assign({}, state, {
		error:action.visible,
        loginError:false
      });
	  break;
    case actions.OPEN_AREA_DIALOG:
    	if(state.area.length==0){
    		return Object.assign({}, state, {
	        	area:action.area
	        });
    	}else{
    		return state;
    	}
  	  break;
    case actions.SET_AREA:
        return Object.assign({}, state, {
        	exclude_area:action.exclude_area
        });
  	  break;
    case actions.SET_GIFT:
    	return Object.assign({}, state, {
        	gift:action.item
        });
    break;
    case actions.REMOVE_GIFT:
    	return Object.assign({}, state, {
        	gift:false
        });
    break;
    case actions.CREATE_NEW:
    	return Object.assign({}, state, {
    			decrease_amount	:0,
    		  discount_rate	:0,
    		  end_time	:"",
    		  exclude_area	:[],
    		  gift_id	:0,
    		  gift_name	:"",
    		  gift_url	:"",
    		  is_amount_multiple	:'false',
    		  is_amount_over	:true,
    		  is_decrease_money	:true,
    		  is_discount	:false,
    		  is_free_post	:'false',
    		  is_item_count_over	:false,
    		  is_item_multiple	:'false',
    		  is_send_gift	:'false',
    		  is_shop_member	:'false',
    		  is_user_tag	:'false',
    		  item_count	:0,
    		  name	:"",
    		  participate_range	:"1",
    		  shop_member_level	:0,
    		  start_time	:"",
    		  total_price	:0,
    		  type	:1,
    		  user_tag	:"",
    		  activityId:"",
    		  dbId:""
        });
    break;
    default:
      return state;
  }
}

